home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / other / dopus412-gpl / library / strings.c < prev    next >
C/C++ Source or Header  |  2000-02-28  |  2KB  |  84 lines

  1. /*
  2.  
  3. Directory Opus 4
  4. Original GPL release version 4.12
  5. Copyright 1993-2000 Jonathan Potter
  6.  
  7. This program is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU General Public License
  9. as published by the Free Software Foundation; either version 2
  10. of the License, or (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. All users of Directory Opus 4 (including versions distributed
  22. under the GPL) are entitled to upgrade to the latest version of
  23. Directory Opus version 5 at a reduced price. Please see
  24. http://www.gpsoft.com.au for more information.
  25.  
  26. The release of Directory Opus 4 under the GPL in NO WAY affects
  27. the existing commercial status of Directory Opus 5.
  28.  
  29. */
  30.  
  31. #include "dopuslib.h"
  32.  
  33. __asm __saveds DoStrCombine(register __a0 char *buf,
  34.     register __a1 char *one,
  35.     register __a2 char *two,
  36.     register __d0 int lim)
  37. {
  38.     register int a;
  39.  
  40.     a=strlen(one); if (a>=lim) a=lim-1;
  41.     strncpy(buf,one,a); buf[a]=0;
  42.     return(StrConcat(buf,two,lim));
  43. }
  44.  
  45. __asm __saveds DoStrConcat(register __a0 char *buf,
  46.     register __a1 char *cat,
  47.     register __d0 int lim)
  48. {
  49.     register int a,b;
  50.  
  51.     a=strlen(cat); b=strlen(buf);
  52.     --lim;
  53.     if (a+b<lim) {
  54.         strncpy(&buf[b],cat,a); buf[b+a]=0;
  55.         return(1);
  56.     }
  57.     if (lim>b) strncpy(&buf[b],cat,lim-b); buf[lim]=0;
  58.     return(0);
  59. }
  60.  
  61. __asm __saveds DoAtoh(register __a0 unsigned char *buf,
  62.     register __d0 int len)
  63. {
  64.     int a,c,d,e,f;
  65.  
  66.     c=e=0;
  67.     for (a=0;;a++) {
  68.         if (!buf[a] || !((buf[a]>='0' && buf[a]<='9') || (buf[a]>='a' && buf[a]<='f') ||
  69.             (buf[a]>='A' && buf[a]<='F'))) break;
  70.         if ((++e)==len) break;
  71.     }
  72.     if (e==0) return(0);
  73.     f=1;
  74.     for (a=1;a<e;a++) f*=16;
  75.     for (a=0;a<e;a++) {
  76.         if (buf[a]>='0' && buf[a]<='9') d=buf[a]-'0';
  77.         else if (buf[a]>='A' && buf[a]<='F') d=10+(buf[a]-'A');
  78.         else if (buf[a]>='a' && buf[a]<='f') d=10+(buf[a]-'a');
  79.         c+=(d*f);
  80.         f/=16;
  81.     }
  82.     return(c);
  83. }
  84.